<template>
  <div>
    <Header></Header>
    <div class="crumb">
      <div class="w">
        <div class="crumb-con">
          <a class="link" href="./index.html">睿购商城</a>
          <span>&gt;</span>
          <span class="link-text">购物车</span>
        </div>
      </div>
    </div>
    <div class="cart-wrap w">
      <div class="cart-header">
        <table class="cart-table">
          <tbody>
          <tr>
            <th class="cart-cell cell-check">
              <label>
                <input type="checkbox" class="cart-select-all" checked="checked">
                <span>全选</span>
              </label>
            </th>
            <th class="cart-cell cell-info">商品信息</th>
            <th class="cart-cell cell-price">单价</th>
            <th class="cart-cell cell-count">数量</th>
            <th class="cart-cell cell-total">合计</th>
            <th class="cart-cell cell-opera">操作</th>
          </tr>
          </tbody>
        </table>
      </div>
      <div class="cart-list">
        <table class="cart-table" data-product-id="107" data-checked="1" >
          <tbody>
          <tr v-for="item in cartContent">
            <td class="cart-cell cell-check">
              <input type="checkbox" class="cart-select" checked="checked">
            </td>
            <td class="cart-cell cell-img">
              <a href="./detail.html?productId=107" target="_blank">
                <img class="p-img" src="../assets/tv-ssmall.jpg">
              </a>
            </td>
            <td class="cart-cell cell-info">
              <a class="link p-name" href="./detail.html?productId=107" target="_blank">{{item.product["name"]}}</a>
            </td>
            <td class="cart-cell cell-price">{{item.product["price"]}}</td>
            <td class="cart-cell cell-count">
              <span class="count-btn" data-opera-type="minus">-</span>
              <input class="count-input" data-max="9987" value="1">
              <span class="count-btn" data-opera-type="plus">+</span>
            </td>
            <td class="cart-cell cell-total">{{item.productTotalPrice}}</td>
            <td class="cart-cell cell-opera">
              <a class="link cart-delete">删除</a>
            </td>
          </tr>
          </tbody>
        </table>
      </div>
      <div class="cart-footer clear">
        <div class="select-con">
          <label>
            <input type="checkbox" class="cart-select-all" checked="checked">
            <span>全选</span>
          </label>
        </div>
        <div class="delete-con">
          <a class="cart-delete-seleced link">
            <i class="fa fa-trash-o" aria-hidden="true"></i>
            <span>删除选中</span>
          </a>
        </div>
        <div class="submit-con">
          <span>总价：</span> <span class="submit-total">{{cartTotalPrice}}</span>
          <router-link :to="{'name':'orderConfirm',}">
            <span class="btn submit-btn">去结算</span>
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import Header from '../components/Header'
  export default {
        name: "Cart",
        components: {Header},
        data(){
          return{
            cartContent:{},
            cartTotalPrice:''
          }
        },
        created() {
          //判断是否从商品详情页添加到购物车链接进入
          if(this.$route.query.productId != null && this.$route.query.count !=null ){
            this.cartAdd();
          }else{
            this.getCartList();
        }
          },
    methods:{
      getCartList:function () {
            this.axios.get('/cart/list.do')
              .then( (response) => {
                this.cartTotalPrice = response.data.data.cartTotalPrice;
                console.log({"response.data":response.data});
                this.cartContent = response.data.data.data;
                console.log(this.cartContent)
              })
    },
      cartAdd:function () {
        this.axios.get('/cart/add.do', {params:{'productId':this.$route.query.productId,'count':this.$route.query.count}})
          .then( (response) => {
            this.cartTotalPrice = response.data.data.cartTotalPrice;
            console.log({"添加后的购物车列表":response.data.data});
            this.cartContent = response.data.data.data;
          })
      }
  }
  }

</script>

<style scoped>
  .cart-table{
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #ebebeb;
    margin-bottom: 10px;
  }
  /* header */
  .cart-header{
    background: #eee;
  }
  .cart-header .cart-cell{
    height: 40px;
    line-height: 40px;
  }
  .cart-table .cell-check{
    width: 6%;
    text-align: left;
    padding-left: 20px;
  }
  .cart-table .cell-img{
    width: 10%;
    text-align: left;
  }
  .cart-table .cell-img .p-img{
    margin: 10px 0;
    width: 80px;
    height: 80px;
    border: 1px solid #ddd;
  }
  .cart-table .cell-info{
    width: 35%;
    text-align: left;
  }
  .cart-header .cell-info{
    width: 45%;
    padding-left: 106px;
  }
  .cart-table .cell-price{
    width: 10%;
    text-align: center;
  }
  .cart-table .cell-count{
    width: 15%;
    text-align: center;
  }
  .cart-table .cell-count .count-input{
    width: 60px;
    height: 28px;
    line-height: 28px;
    border: 1px solid #ddd;
    text-align: center;
    vertical-align: middle;
    outline: none;
    color: #333;
  }
  .cart-table .cell-count .count-btn{
    display: inline-block;
    width: 20px;
    height: 28px;
    line-height: 28px;
    border: 1px solid #ddd;
    vertical-align: middle;
    cursor: pointer;
    background: #fff;
    -moz-user-select : none;
    -webkit-user-select : none;
    -ms-user-select : none;
    user-select : none;
  }
  .cart-table .cell-total{
    width: 14%;
    text-align: center;
    font-weight: bold;
  }
  .cart-table .cell-opera{
    width: 10%;
    text-align: center;
  }

  /* footer */
  .cart-footer{
    position: relative;
    line-height: 50px;
    background: #eee;
    overflow: hidden;
  }
  .cart-footer .select-con{
    float: left;
    padding-left: 20px;
  }
  .cart-footer .delete-con{
    float: left;
    margin-left: 20px;
  }
  .cart-footer .submit-con{
    float: right;
  }
  .cart-footer .submit-con .submit-total{
    font-size: 18px;
    color: #FF8800;
    font-weight: bold;
    margin-right: 30px;
    vertical-align: middle;
  }
  .cart-footer .submit-con .btn-submit{
    width: 80px;
    text-align: center;
    height: 50px;
    line-height: 50px;
  }
  /* 閿欒淇℃伅 */
  .err-tip{
    height: 60px;
    line-height: 60px;
    color: #f60;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    background: #eee;
  }
</style>
